<?php

/**
 * 前台 新闻 模块 Controller
 * ============================================================================
 * TBlog TBlog博客系统　BY Tmac PHP MVC framework
 * $Author: zwt007 $  <zwttmac@qq.com>
 * $Id: news.php 39 2011-07-11 17:12:35Z zwt007 $
 * http://www.t-mac.org；
 */
class newsAction extends Action
{

    private $tmp_model;
    private $show_model;
    private $article_model;
    private $index_model;

    public function _init()
    {
        $this->assign('action', $_GET['TMAC_ACTION']);
        $this->tmp_model = Tmac::model('news');
        $this->show_model = Tmac::model('show');
        $this->index_model = Tmac::model('index');
        $this->article_model = Tmac::model('article', 'admin');

        $this->M('index')->getCommon();
    }

    public function index()
    {
        $name = 'news';
        $catinfo = $this->show_model->getCategoryInfo($name);        
        $cid = $catinfo['cat_id'];        
        //取文章信息
        $list = $this->tmp_model->getArticleList('', $cid);
                                
        $this->assign('cid', $cid);
        $this->assign('catinfo', $catinfo);                
        $this->assign('list', $list);        
        $this->V('news_list');
    }

    public function show()
    {
        $name = $this->H($this->getParam('name'));
        $name = empty($name) ? 'news' : $name;
        $catinfo = $this->show_model->getCategoryInfo($name);
        $aid = intval($this->getParam('aid'));
        if (empty($aid)) {
            $this->redirect('请选择文章');
            exit();
        }

        //增加一次点击数
        $this->show_model->saveArticleClick($aid);
        $info = $this->article_model->getArticleInfo($aid);
                
        $this->assign('info', $info);
        $this->assign('catinfo', $catinfo);
        $this->assign('name', $name);
        $this->V('news_show');
    }

}